﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;

namespace MvcControlsToolkit
{
    public class PieRendererOptions : RendererOptions
    {
        /// <summary>
        /// True to show data labels on slices
        /// </summary>
        public bool ShowDataLabels
        {
            get
            {
                if (Attributes.ContainsKey("showDataLabels"))
                    return Boolean.Parse(GetString("showDataLabels"));
                else
                    return true;
            }

            set
            {
                Attributes["showDataLabels"] = value.ToString().ToLower();
            }
        }

        /// <summary>
        /// Padding between the pie and plot edges, legend, etc
        /// </summary>
        public int Padding
        {
            get
            {
                if (Attributes.ContainsKey("padding"))
                    return int.Parse(Attributes["padding"]);
                else return 0;
            }
            set { Attributes["padding"] = value.ToString().ToLower(); }
        }

        /// <summary>
        /// Angular spacing between pie slices in degrees
        /// </summary>
        public int SliceMargin
        {
            get
            {
                if (Attributes.ContainsKey("sliceMargin"))
                    return int.Parse(Attributes["sliceMargin"]);
                else return 0;
            }
            set { Attributes["sliceMargin"] = value.ToString().ToLower(); }
        }

        /// <summary>
        /// Angle to start drawing pie in degrees
        /// </summary>
        public int StartAngle
        {
            get
            {
                if (Attributes.ContainsKey("startAngle"))
                    return int.Parse(Attributes["startAngle"]);
                else return 0;
            }
            set { Attributes["startAngle"] = value.ToString().ToLower(); }
        }

        /// <summary>
        /// True or false, wether to fil the slices
        /// </summary>
        public bool Fill
        {
            get
            {
                if (Attributes.ContainsKey("fill"))
                    return Boolean.Parse(GetString("fill"));
                else
                    return true;
            }

            set
            {
                Attributes["fill"] = value.ToString().ToLower();
            }
        }

        /// <summary>
        /// Format string for data labels
        /// </summary>
        public string DataLabelFormatString
        {
            get { return GetString("dataLabelFormatString"); }
            set { SetString("dataLabelFormatString", value); }
        }

        /// <summary>
        /// Threshhold in percentage (0-100) of pie area, below which no label will be displayed
        /// </summary>
        public int DataLabelThreshold
        {
            get
            {
                if (Attributes.ContainsKey("dataLabelThreshold"))
                    return int.Parse(Attributes["dataLabelThreshold"]);
                else return 0;
            }
            set { Attributes["dataLabelThreshold"] = value.ToString().ToLower(); }
        }

        /// <summary>
        /// A Multiplier (0-1) of the pie radius which controls position of label on slice
        /// </summary>
        public double DataLabelPositionFactor
        {
            get
            {
                if (Attributes.ContainsKey("dataLabelPositionFactor"))
                    return int.Parse(Attributes["dataLabelPositionFactor"]);
                else return 0.08;
            }
            set { Attributes["dataLabelPositionFactor"] = value.ToString().ToLower(); }
        }

        /// <summary>
        /// Number of pixels to slide the label away from (+) or toward (-) the center of the pie
        /// </summary>
        public int DataLabelNudge
        {
            get
            {
                if (Attributes.ContainsKey("dataLabelNudge"))
                    return int.Parse(Attributes["dataLabelNudge"]);
                else return 2;
            }
            set { Attributes["dataLabelNudge"] = value.ToString().ToLower(); }
        }

        /// <summary>
        /// True to center the data label at its position. False to set the inside facing edge of the label at its position
        /// </summary>
        public bool DataLabelCenterOn
        {
            get
            {
                if (Attributes.ContainsKey("dataLabelCenterOn"))
                    return Boolean.Parse(GetString("dataLabelCenterOn"));
                else
                    return true;
            }

            set
            {
                Attributes["dataLabelCenterOn"] = value.ToString().ToLower();
            }
        }        
    }
}
